package com.to8to.kitt;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
import io.netty.util.ReferenceCountUtil;



public class ThriftLengthFieldBasedFrameDecoder extends LengthFieldBasedFrameDecoder{
	
	public static int MAX_FRAME_LENGTH = 128 * 1024 * 1024;
	
	public ThriftLengthFieldBasedFrameDecoder() {
		this( MAX_FRAME_LENGTH );
	}
	
	public ThriftLengthFieldBasedFrameDecoder(int maxFrameLength) {
		super( maxFrameLength, 0, 4, 0, 4, true);
	}
	
    protected ByteBuf extractFrame(ChannelHandlerContext ctx, ByteBuf buffer, int index, int length) {
    	ReferenceCountUtil.retain(buffer);
    	return buffer.slice(index, length);
    }
}
